import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;


public class ASyncConsumer {

	public static int i = 0;
	public static int n;
	public static JFrame frame = new JFrame("动态随机数折线图");
	public static RealTimeChart realTimeChart = new RealTimeChart("随机数折线图", "随机数", "数值");


	public static void main(String[] args) throws JMSException {
		String brokerURL = "tcp://localhost:61616";
		ConnectionFactory factory = null;
		Connection connection = null;
		Session session = null;
		Topic topic = null;
		MessageConsumer messageConsumer = null;
//		Message message = null;
//		Singnal_Anasis singnal_anasis = new Singnal_Anasis();
//		final double[] average = new double[1];
//		final double[] me = new double[1];
//		final double[] max = new double[1];
//		final double[] min = new double[1];
//		double[] msglist = new double[singnal_anasis.getN()];

		try {
			factory = new ActiveMQConnectionFactory(brokerURL);
			connection = factory.createConnection();
			connection.start();
			session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
			topic = session.createTopic("Random_plot_package");

			messageConsumer = session.createConsumer(topic);
			Consumer_Listener consumer_listener = new Consumer_Listener();
			Scanner in = new Scanner(System.in);
			System.out.println("请输入一次传送数据包的大小：");
			n = in.nextInt();
			consumer_listener.equaln(n);

			frame.getContentPane().add(realTimeChart, new BorderLayout().CENTER);
			frame.pack();
			frame.setVisible(true);
			realTimeChart.getrandom_number(0.0000);
			(new Thread(realTimeChart)).start();
			frame.addWindowListener(new WindowAdapter() {
				@Override
				public void windowClosing(WindowEvent windowevent) {
					System.exit(0);
				}
			});
			messageConsumer.setMessageListener(consumer_listener);
		} catch (Exception e){
			e.printStackTrace();
		}
	}
}
